<template>
  <div>
    <el-dialog :visible.sync="visible" width="80%" append-to-body>
<!--      <el-row :gutter="12" class="pd-tb-10-px">-->
<!--        <el-col :span="4"> <v2-select :config="selectConfig" v-model="lang"></v2-select></el-col>-->
<!--        <el-col :span="2"><el-button @click="fy" size="small" :disabled="isLoad">-->
<!--          <i class="el-icon-loading" v-if="isLoad"></i><span>翻译</span>-->
<!--        </el-button></el-col>-->
<!--      </el-row>-->
      <el-row :gutter="12">
        <el-col :span="12">
          <p>中文</p>
          <el-input type="textarea" v-model="prompt"  :autosize="{ minRows: 16}"></el-input>
        </el-col>
        <el-col :span="12">
          <p>英文</p>
          <el-input type="textarea" v-model="promptEn" :autosize="{ minRows: 16}"></el-input>
        </el-col>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import Dialog from "@/commons/Dialog";
import Service from "api/Service";
import http from "network/http";
import util from "utils/util";
export default {
  name: "promptBox",
  mixins:[Dialog] ,
  props: {
    prompt: "",
    promptEn: '',
    value: false
  },
  data(){
    return {
      lang: 'zh_CN' ,
      isLoad: false ,
      selectConfig:{
        options: [
          {
            label: "中文",
            value: 'zh_CN'
          },
          {
            label: "英文",
            value: 'en_US'
          }
        ]
      },
      promptText: ""
    }
  },
  watch:{
  },
  methods:{
    fy(){
      if(util.isEmpty(this.prompt)){
        this.$message.error("请输入内容") ;
        return
      }
      let array = this.prompt.split("\n")
      let allP = []
      this.isLoad = true
      array.forEach((item)=>{
        allP.push(
            http.post("/SD/physton_prompt/translates",{
              api : "baidu_free" ,
              api_config: {} ,
              from_lang: this.lang ,
              to_lang :  util.ifTruthy(this.lang === "zh_CN" , "en_US", "zh_CN") ,
              texts : item
            })
        )
      })
      Promise.all(allP).then(res=>{
        this.promptText = res.map(item=>item.translated_text).join("\n")
        this.isLoad = false ;
      })
    }
  }
}
</script>

<style scoped>

</style>